package com.liush.srb.core.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liush.srb.base.result.ResponseVo;
import com.liush.srb.core.pojo.entity.LendItem;
import com.liush.srb.core.pojo.vo.InvestVO;
import com.liush.srb.core.service.LendItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: liush
 * @CreateTime: 2023-04-12  19:20
 * @Description: 标的出借记录表 前端控制器
 */
@RestController
@RequestMapping("/api/core/lendItem")
public class ApiLendItemController {

    @Resource
    LendItemService lendItemService;

    @ApiOperation("投资")
    @PostMapping("invest")
    public ResponseVo invest(@RequestBody InvestVO investVO,
                             @RequestHeader(value = "token", required = false) String token) {
        //返回自动提交的表单字符串
        String form = lendItemService.invest(investVO, token);
        return ResponseVo.ok().data("form", form);
    }

    //http://192.168.1.171/api/core/lendItem/notify
    @ApiOperation("投资回调接口：投资人在hfb中操作投资之后hfb的回调")
    @PostMapping("notify")
    public String investNotify(@RequestParam Map<String, Object> map) {
        return lendItemService.investNotify(map);
    }

    @ApiOperation("查询投资人投资记录")
    @GetMapping("{pageNum}/{pageSize}")
    public ResponseVo list(@RequestHeader(value = "token", required = false) String token,
                           @PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize) {
        Page<LendItem> page = lendItemService.investList(token, pageNum, pageSize);
        return ResponseVo.ok().data("page", page);
    }
}
